﻿package command {
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	public class AlignCommand implements ICommand {
		private var inputField:TextField;
		private var index:Array;
		private var align:Array;
		private var newAlign:String;
		
		public function AlignCommand(inputField:TextField, index:Array, align:Array, newAlign:String):void {
			this.inputField = inputField;
			this.index = index;
			this.align = align;
			this.newAlign = newAlign;
		}
		
		public function redo():void {
			for (var i:int = 0; i < index.length; i++) {
				var tf:TextFormat = inputField.getTextFormat(index[i], index[i] + 1);
				tf.align = newAlign;
				inputField.setTextFormat(tf, index[i], index[i] + 1);
			}
		}
		public function undo():void {
			for (var i:int = 0; i < index.length; i++) {
				var tf:TextFormat = inputField.getTextFormat(index[i], index[i] + 1);
				tf.align = align[i];
				inputField.setTextFormat(tf, index[i], index[i] + 1);
			}
		}
	}
}